Enter an integer: 17 The number 17 is positive positive numbers are greater or equal to zero Good-bye for now
The false block was executed because the answer to the
question (num < 0) was false.
The false block consists of two statements.
Here is how an outline of how make a two-way decision:
... statements done before the decision
if ( condition )
.... // true branch
else
.... // false branch
... statements done after the branch comes back together
Here are some details:
The condition can compare what is held in a variable to other values.
You can use the comparisons: <, >, and so on.
(More about these later.)
The first statement after the false branch will be executed no matter which
branch is chosen.
The if-else is like a fork in the road,
but the road always comes together again.
Do you believe that the following section of a program is correct?
if ( num < 0 )
System.out.println("The number " + num + " is negative");
else
System.out.println("The number " + num + " is positive");
System.out.print ("positive numbers are greater ");
System.out.println("or equal to zero ");
System.out.println("Good-bye for now");